package kn.cstf2.transition.Server;

import kn.cstf2.login.Server.*;
import kn.cstf2.global.Utils.*;
import kn.cstf2.login.Server.*;
import kn.cstf2.global.Utils.CstF2Exception;


import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;

import com.mx.kn.cstf2.dto.JoindocumenttransitionBean;

import kn.cstf2.transition.Bean.*;


/**
 * @author Izhar Gamaliel Hernandez Cruz Programador Java Junior Desarrollado para
 * Kuehne + Nagel
 */
public class AdaptadorTransition {



   
  public static TransitionBean obtenerTransitionBean(ResultSet rs) {
        TransitionBean  transitionBean = new TransitionBean();
        try {
            while (rs.next()) {
                
                transitionBean.setId(rs.getInt("id"));
                transitionBean.setKnkey(rs.getInt("knkey"));
               
            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return transitionBean;
    }

   
  public static Boolean obtenerVoBosJoinDocumentTransition(ResultSet rs) {
	  JoindocumenttransitionBean  joindocumenttransitionBean = new JoindocumenttransitionBean();
        ArrayList<Boolean> checboxVobo = new ArrayList<Boolean>();
        Boolean vobo = new Boolean(false);
        try {
            while (rs.next()) {
                vobo=(rs.getBoolean("vobo"));
            }
            
            //joindocumenttransitionBean.setCheckboxesVoBo(checboxVobo);
           
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        //return joindocumenttransitionBean;
        return vobo;
    }

    public static AsignIfownerStkBean obtenerIfowner(ResultSet rs) {
        AsignIfownerStkBean asignIfownerStkBean = null;
        try {
            if (rs.next()) {
                asignIfownerStkBean = new AsignIfownerStkBean();
                asignIfownerStkBean.setIfownwer(rs.getString("ifowner"));
          
                
            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return asignIfownerStkBean;
    }
    
    
    public static TransitionBean obtenerDataTransition(ResultSet rs) {
        TransitionBean transitionBean = null;
        try {
            if (rs.next()) {
                transitionBean = new TransitionBean();
                transitionBean.setId(rs.getInt("id"));
                transitionBean.setKnkey(rs.getInt("knkey"));
                transitionBean.setStatus(rs.getString("status"));
                transitionBean.setLog(rs.getString("log"));
                
            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return transitionBean;
    }
    
    
    public static TransitionBean obtenerStatusImplementation(ResultSet rs) {
        TransitionBean transitionBean = null;
        try {
            if (rs.next()) {
                transitionBean = new TransitionBean();
               
                transitionBean.setStatusimple(rs.getString("statusimple"));
               
            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return transitionBean;
    }
    
    public static TransitionBean obtenerStatusTransition(ResultSet rs) {
        TransitionBean transitionBean = null;
        try {
            if (rs.next()) {
                transitionBean = new TransitionBean();
               
                transitionBean.setStatus(rs.getString("status"));
               
            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return transitionBean;
    }
    

    public static TransitionBean obtenerDataTransitionIdKnkey(ResultSet rs) {
        TransitionBean transitionBean = null;
        try {
            if (rs.next()) {
                transitionBean = new TransitionBean();
                transitionBean.setId(rs.getInt("id"));
                //transitionBean.setKnkey(rs.getInt("knkey"));
          
            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return transitionBean;
    }
    
    
        public static T_clientesDataFromStkBean obtenerDataFromKnkeyFromStk(ResultSet rs) {
        T_clientesDataFromStkBean t_clientesFromStkBean = null;
        try {
            if (rs.next()) {
                t_clientesFromStkBean = new T_clientesDataFromStkBean();
                t_clientesFromStkBean.setCompanyname(rs.getString("companyname"));
                t_clientesFromStkBean.setComercialname(rs.getString("comercialname"));
                t_clientesFromStkBean.setCompaddress(rs.getString("compaddress"));
                t_clientesFromStkBean.setCiudad(rs.getString("ciudad"));
          
                
            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return t_clientesFromStkBean;
    }

       public static DocumentsBean obtenerDocumentName(ResultSet rs) {
        DocumentsBean documentsBean = new DocumentsBean();; 
        try {
            if (rs.next()) {               
                documentsBean.setName(rs.getString("name"));                 
            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return documentsBean;
    }   
       
       public static DocumentsBean obtenerDocumentId(ResultSet rs) {
        DocumentsBean documentsBean = new DocumentsBean();; 
        try {
            if (rs.next()) {               
                documentsBean.setId(rs.getInt("id"));                 
            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return documentsBean;
    }   
        
       
       
        public static JoindocumenttransitionBean obtenerJoindocumenttransitionData(ResultSet rs) {
        	JoindocumenttransitionBean joindocumenttransitionBean = null; 
        try {
            if (rs.next()) {
                joindocumenttransitionBean = new JoindocumenttransitionBean();
                joindocumenttransitionBean.setVobo(rs.getBoolean("vobo"));    
                joindocumenttransitionBean.setUploaded(rs.getBoolean("uploaded"));
                joindocumenttransitionBean.setDetails(rs.getString("details"));    
               
            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return joindocumenttransitionBean;
    }     
       
       
  public static String obtenerJoindocumenttransitionDetails(ResultSet rs) {
        String detailsd = null; 
        try {
            if (rs.next()) {
                
               detailsd= rs.getString("details");    
               
            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return detailsd;
    }     
    
        
      public static PersonalBean obtenerDataPersonal(ResultSet rs) {
        PersonalBean personalBean = null; 
        try {
            while (rs.next()) {
                personalBean = new PersonalBean();
                personalBean.setBf(rs.getString("bf"));    
                personalBean.setName(rs.getString("name"));    
                personalBean.setEmail(rs.getString("email"));    
                personalBean.setPhone(rs.getString("phone"));    
               
            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return personalBean;
    }  
      
       public static PersonalBean obtenerDataPersonalByName(ResultSet rs) {
        PersonalBean personalBean = null; 
        try {
            if (rs.next()) {
                personalBean = new PersonalBean();
                personalBean.setId(rs.getInt("id"));   
                personalBean.setBf(rs.getString("bf"));    
                personalBean.setName(rs.getString("name"));    
                personalBean.setEmail(rs.getString("email"));    
                personalBean.setPhone(rs.getString("phone"));    
               
            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return personalBean;
    }  
            
      
       public static ArrayList<PersonalBean> obtenerDataPersonalByKnkey(ResultSet rs) {
        ArrayList<PersonalBean> personalListbyKnkeyTransition = new ArrayList<PersonalBean>(); 
        PersonalBean personalBean ;
        try {
           while (rs.next()) {
                personalBean = new PersonalBean();
                personalBean.setId(rs.getInt("id"));   
                personalBean.setBf(rs.getString("bf"));    
                personalBean.setName(rs.getString("name"));    
                personalBean.setEmail(rs.getString("email"));    
                personalBean.setPhone(rs.getString("phone"));    
                personalBean.setKnkey(rs.getInt("knkey"));    
                personalListbyKnkeyTransition.add(personalBean);
               
            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return personalListbyKnkeyTransition;
    }  
            
      
       public static ArrayList<PersonalBean> obtenerDataPersonalByIdp(ResultSet rs) {
        ArrayList<PersonalBean> personalListbyKnkeyTransition = new ArrayList<PersonalBean>(); 
        PersonalBean personalBean ;
        try {
           while (rs.next()) {
                personalBean = new PersonalBean();
                personalBean.setId(rs.getInt("id"));   
                personalBean.setBf(rs.getString("bf"));    
                personalBean.setName(rs.getString("name"));    
                personalBean.setEmail(rs.getString("email"));    
                personalBean.setPhone(rs.getString("phone"));    
                personalBean.setKnkey(rs.getInt("knkey"));    
                personalListbyKnkeyTransition.add(personalBean);
               
            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return personalListbyKnkeyTransition;
    }  
      
       public static PersonalBean obtenerDataPersonalById(ResultSet rs) {
        ArrayList<PersonalBean> personalListbyKnkeyTransition = new ArrayList<PersonalBean>(); 
        PersonalBean personalBean = new PersonalBean();
        try {
           while (rs.next()) {
                
                personalBean.setId(rs.getInt("id"));   
                personalBean.setBf(rs.getString("bf"));    
                personalBean.setName(rs.getString("name"));    
                personalBean.setEmail(rs.getString("email"));    
                personalBean.setPhone(rs.getString("phone"));    
                personalBean.setKnkey(rs.getInt("knkey"));    
                
            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return personalBean;
    }  
            
        
       
       public static JoindocumenttransitionBean obtenerIdsFromJoindocumenttransition(ResultSet rs) {
        JoindocumenttransitionBean joindocumenttransitionBean = new JoindocumenttransitionBean(); 
        try {
            if (rs.next()) {
                
                joindocumenttransitionBean.setId(rs.getInt("id"));    

            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return joindocumenttransitionBean;
    }     
      
       
       public static JoindocumenttransitionBean insertarRelacionEnJoindocumenttransition(ResultSet rs) {
        JoindocumenttransitionBean joindocumenttransitionBean = new JoindocumenttransitionBean(); 
        try {
            if (rs.next()) {
                
                joindocumenttransitionBean.setId(rs.getInt("id"));    

            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return joindocumenttransitionBean;
    }  
       
       
        public static JoinPersonTransitionBean insertarJoinPersonTransition(ResultSet rs) {
        JoinPersonTransitionBean joinPersonTransitionBean = new JoinPersonTransitionBean(); 
        try {
            while (rs.next()) {
                
                joinPersonTransitionBean.setId(rs.getInt("id"));    

            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return joinPersonTransitionBean;
              }
              
              
       public static JoindocumenttransitionBean actualizarVoBoEnJoindocumenttransition(ResultSet rs) {
        JoindocumenttransitionBean joindocumenttransitionBean = new JoindocumenttransitionBean(); 
        try {
            if (rs.next()) {
                
                joindocumenttransitionBean.setVobo(rs.getBoolean("vobo"));    

            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return joindocumenttransitionBean;
    }     
       
      
        public static TransitionBean actualizarLogEnTransition(ResultSet rs) {
        TransitionBean transitionBean = new TransitionBean(); 
        try {
            if (rs.next()) {
                
                transitionBean.setLog(rs.getString("log"));    

            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return transitionBean;
    } 
        
        public static ArrayList<String> obtenerListaNombrePersonal(ResultSet rs) {
        ArrayList<String>name=new ArrayList<String>(); 
        try {
            while (rs.next()) {
                
                
                name.add(rs.getString(1));
               
            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return name;
    }   
        
        public static ArrayList<String> obtenerListaNombreDePersonalByKnkeyTransition(ResultSet rs) {
        ArrayList<String>name=new ArrayList<String>(); 
        try {
            while (rs.next()) {
                
                
                name.add(rs.getString(1));
               
            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return name;
    }   
       
      
     
        public static Integer verificarCountRelationJoinusertransition(ResultSet rs) {
        //Integer cout = new Integer(0); 
        int cout = 0;
        try {
            while (rs.next()) {
                
                
                cout=(rs.getInt(1));
               
            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return cout;
    }   
        
       
        
       public static String obtenerTransitionLog(ResultSet rs) {
        //Integer cout = new Integer(0); 
        String Tlog="";
        try {
            if(rs.next()) {
                
                
                Tlog=(rs.getString("log"));
               
            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return Tlog;
    }    
        
}
   